package com.woniuxy.commons.exception;

import com.woniuxy.commons.entity.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author: luojiwei
 * @date: 2020/7/18 15:37
 * @description: 处理异常的类
 */
public class BzeducationException {
    @ExceptionHandler
    @ResponseBody
    public ResponseEntity<String> exceptionHandler(Exception e) {
        e.printStackTrace();
        ResponseEntity<String> responseEntity = new ResponseEntity();
        responseEntity.setCode(ResponseEntity.FAIL);
        if (e instanceof StudentNotExistException) {
            responseEntity.setMsg("学生不存在");
        } else if (e instanceof CannotChangeClassException) {
            responseEntity.setMsg("原班与待转入班相同，不能转班");
        } else if (e instanceof StudentExistAwaitClassException) {
            responseEntity.setMsg("学生已存在待转入的班级");
        } else if (e instanceof NoAuthorityException) {
            responseEntity.setMsg("你没有权限查看这个视频");
        } else if (e instanceof NoBadStusException) {
            responseEntity.setMsg("没有差生");
        } else if (e instanceof StudentInChangeClassException) {
            responseEntity.setMsg("该学生还有转班申请未处理");
        } else if (e instanceof CodeException) {
            responseEntity.setMsg("验证码不正确");
        } else {
            responseEntity.setMsg("系统维护中");
        }
        return responseEntity;
    }
}
